<template>
	<view class="login">
		<!-- 账号 -->
		<view class="account">
			<image src="/static/pages/index/loginImg.png" mode=""></image>
			<view class="accountContent">
				<image src="/static/pages/index/userMessage.png" class="userImg" mode=""></image>
				<input type="text" v-model="usetMessage" placeholder="请输入账号" placeholder-style="color:#ffffff;font-size:28rpx;" class="accInput" />
			</view>
		</view>
		<!-- 密码 -->
		<view class="passWord">
			<image src="/static/pages/index/loginImg.png" mode=""></image>
			<view class="passWordContent">
				<image src="/static/pages/index/passWordImg.png" class="possWordImg" mode=""></image>
				<input type="text" password="true" v-model="password" placeholder="请输入密码" placeholder-style="color:#ffffff;font-size:28rpx;" class="possWordInput" />
			</view>
		</view>
		<!-- 登录 -->
		<view class="login" @click="loginClick">
			<image src="/static/pages/index/loginImg1.png" mode="" class="loginImg"></image>
			<view class="loginBox">登录</view>
		</view>
		<!-- 微信登录 -->
		<view class="wxLogin">
			<view class="wxNav">
				<view class="wxNavWire1"></view>
				<view class="wxNavWord">其他登录方式</view>
				<view class="wxNavWire2"></view>
			</view>
		</view>
		<view class="wxLoginImg" @click="wxLoginClick">
			<view class="wxLoginImgContent">
				<image src="/static/pages/index/wxLoginImg.png" mode="" class="loginWx"></image>
				<view class="wxLoginWord">微信一键登录</view>
			</view>
		</view>
	</view>
</template>

<script>

import { login,wxLogins } from '@/request/api.js';
export default {
	data() {
		return {
			usetMessage: '', //账号
			password: '', //密码
			type: ''
		};
	},
	onLoad(options) {
		console.log(options);
		this.type = options.type;
	},
	methods: {
		//普通登录
		loginClick() {
			let _this = this;
			if (_this.usetMessage == '' || _this.password == '') {
				uni.showToast({
					title: '请先填写完整信息',
					icon: 'none'
				});
			} else {
				// let data = {
				// 	usetMessage:_this.usetMessage,
				// 	password:_this.usetMessage
				// }
				// login(data).then(res=>{
				// 	if(){

				// 	}
				// }).catch(err=>{
				// 	console.log(err)
				// })
				if (this.type == 2) {
					login({
						account:this.usetMessage,
						password:this.password,
						type:this.type,
					}).then(res => {
						uni.setStorageSync("login", res.data)
						uni.setStorageSync('mobile',this.usetMessage)
						uni.setStorageSync('password',this.password)
						console.log(res);
						uni.showToast({
							title:res.msg,
							icon:"none"
						})
						if(res.code == 1){
							setTimeout(()=>{
								uni.reLaunch({
									url:"/pages/DLR/activity/activity"
								})
							},2000)
						}
					})
				} else if (this.type == 1) {
					login({
						account: this.usetMessage,
						password: this.password,
						type: this.type
					}).then(res => {
						console.log(res);
						uni.setStorageSync('mobile',this.usetMessage)
						uni.setStorageSync('password',this.password)
						uni.setStorageSync('regionMessage', res.data);
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
						if (res.code == 1) {
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/groundPole/distributor/distributor'
								});
							}, 2000);
						}
					});
				}
			}
		},
		// 微信登录
		wxLoginClick() {
			// uni.showToast({
			// 	title:"暂未开放",
			// 	icon:"none"
			// })
			if(this.type == 2){
				wx.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: infoRes => {
						wx.login({
							success(res) {
								
								console.log(res.code,'11111111111111')
								let data = {
									code:res.code,
									apptype:'miniapp',
									type:'2'
								}
								wxLogins(data).then(ress=>{
									console.log(ress)
									if(ress.code==1){
										
										uni.setStorageSync('login', ress.data);
										
										uni.showToast({
											title: ress.msg,
											icon: 'none'
										});
										setTimeout(() => {
											uni.reLaunch({
												url:"/pages/DLR/activity/activity"
											});
										}, 2000);
									}else{
										uni.showToast({
											title:ress.msg,
											icon:"none"
										})
									}
								})
							}
						});
					}
				});
			}else if (this.type == 1) {
				wx.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: infoRes => {
						wx.login({
							success(res) {
								
								console.log(res.code,'11111111111111')
								let data = {
									code:res.code,
									apptype:'miniapp',
									type:'1'
								}
								wxLogins(data).then(ress=>{
									console.log(ress)
									if(ress.code==1){
										
										uni.setStorageSync('regionMessage', ress.data);
										
										uni.showToast({
											title: ress.msg,
											icon: 'none'
										});
										setTimeout(() => {
											uni.reLaunch({
												url: '/pages/groundPole/distributor/distributor'
											});
										}, 2000);
									}else{
										uni.showToast({
											title:ress.msg,
											icon:"none"
										})
									}
								})
							}
						});
					}
				});
			}
			
		}
	}
};
</script>

<style lang="scss">
page {
	background-image: linear-gradient(to bottom, #4884e7, #7caaf6);
	box-sizing: border-box;
}
.login {
	box-sizing: border-box;
	.account {
		width: 693rpx;
		height: 126rpx;
		margin: 263rpx auto 0;
		position: relative;
		image {
			width: 100%;
			height: 100%;
		}
		.accountContent {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			display: flex;
			.userImg {
				width: 68rpx;
				height: 68rpx;
				margin: 30rpx 0 0 26rpx;
			}
			.accInput {
				margin: 40rpx 0 0 18rpx;
				color: #ffffff;
			}
		}
	}
	.passWord {
		width: 693rpx;
		height: 126rpx;
		margin: 62rpx auto 0;
		position: relative;
		image {
			width: 100%;
			height: 100%;
		}
		.passWordContent {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			display: flex;
			.possWordImg {
				width: 68rpx;
				height: 68rpx;
				margin: 30rpx 0 0 26rpx;
			}
			.possWordInput {
				margin: 40rpx 0 0 18rpx;
				color: #ffffff;
			}
		}
	}
	.login {
		width: 527rpx;
		height: 119rpx;
		margin: 120rpx auto 0;
		position: relative;
		.loginImg {
			width: 100%;
			height: 100%;
		}
		.loginBox {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			text-align: center;
			line-height: 119rpx;
			font-size: 30rpx;
			color: #1855f6;
		}
	}
	.wxLogin {
		width: 100%;
		margin-top: 80rpx;
		display: flex;
		.wxNav {
			display: flex;
			margin: 0 auto;
			.wxNavWire1 {
				width: 200rpx;
				height: 2rpx;
				background-color: #ffffff;
				margin-top: 20rpx;
			}
			.wxNavWord {
				font-size: 30rpx;
				color: #ffffff;
				margin: 0 21rpx;
			}
			.wxNavWire2 {
				width: 200rpx;
				height: 2rpx;
				background-color: #ffffff;
				margin-top: 20rpx;
			}
		}
	}
	.wxLoginImg {
		margin-top: 133rpx;
		display: flex;
		justify-content: space-around;
		.wxLoginImgContent {
			display: flex;
			.loginWx {
				width: 56rpx;
				height: 45rpx;
			}
			.wxLoginWord {
				font-size: 30rpx;
				color: #ffffff;
				margin-left: 24rpx;
			}
		}
	}
}
</style>
